/**
 * Created by Administrator on 2017/2/11.
 */
import { Component,OnInit } from '@angular/core';
import { FeditService }   from './factoryedit.serve'



@Component({
    moduleId: module.id,
    selector: 'my-factoryedit',
    templateUrl: 'factoryedit.html',
    providers:[FeditService]
})
export class FactoryeditComponent implements OnInit  {
    constructor(
      private feditService:FeditService
    ){}
      private facinfro='';
      public checked='';
      public addresstype='';
      private errMessage:string;
      private dimen='';
      private dim='';
      public lgge:string;
      public latt:string;
      public facname:string;
      public city:string;
      public web:string;
      public address:string;
     public yhqun:string;
     public catgeryid:string;
     public describe:string;
     public buff:string;
     public dimension:string;
     public email:string;
     public phone:string;
     public able:string;
     public situation:string;
     public note:string;
    addfacedit () {
    this.feditService.facedit(this.facname, this.city, this.web, this.address, this.yhqun,this.checked,this.addresstype, this.catgeryid,this.describe,this.buff,
      this.dimension,this.email,this.phone,this.able,this.situation,this.note,window['lgge'],window['latt'])
      .subscribe(
        res => this.facinfro = res,
        error =>  this.errMessage = <any>error);
       console.log(window['lgge']);
      console.log(window['latt'])
  }
  ngOnInit(){
     this.feditService.selectdimension()
       .subscribe(
         res=>{this.dimen=res['data'];
              this.dim=res['dimensions']
         },
       );
    // 百度地图API功能
    let map = new window['BMap'].Map("allmap");
                                        //获取当前地理位置
    let geolocation = new window['BMap'].Geolocation();
      geolocation.getCurrentPosition(function(r) {
      if(this.getStatus() == 0) {
        let  point = new window['BMap'].Point(r.point.lng, r.point.lat);
        let  marker = new window['BMap'].Marker(point); // 创建标注
        marker.enableDragging();
        map.addOverlay(marker); // 将标注添加到地图中

        map.centerAndZoom(point, 15);
        let  opts = {
          width: 0, // 信息窗口宽度
          height: 0, // 信息窗口高度
          title: "制造厂名称",
          enableMessage: false, //设置允许信息窗发送短息
          enableAutoPan: true,
          enableCloseOnClick: false,
        };
        let  infoWindow = new window['BMap'].InfoWindow("", opts); // 创建信息窗口对象 
        map.openInfoWindow(infoWindow, point); //开启信息窗口
                                                         //获取坐标
        marker.addEventListener("dragend", function() {
          let  p = marker.getPosition(); //获取marker的位置
          window['lgge']=p.lng;
          window['latt']=p.lat;
          console.log("marker的位置是" + p.lng + "," + p.lat);
        });
      } else {
        alert('failed' + this.getStatus());
      }
    }, { enableHighAccuracy: true })
  }
}
